package com.base.jdbc;


import java.sql.*;

/**
 * @author Pretty·Boy
 * @version 1.0
 * @desc:
 * @date 2018/10/20 15:05
 */
public class MainTest {
    public static void main(String args[]) {
        try {
            String sql = "select * from tb_content";
            Connection conn = JdbcUtils.getConnection();
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            ResultSet rs = preparedStatement.executeQuery();
            ResultSetMetaData metaData = rs.getMetaData();
            System.out.println("共有" + metaData.getColumnCount() + "条数据。");

            while (rs.next()) {
                for (int i = 1; i < metaData.getColumnCount() - 1; i++) {
                    System.out.print(metaData.getColumnName(i) + ":" + rs.getObject(i).toString() + "\t");
                }
                System.out.println();
                System.out.println("---------------------");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close();
        }

    }
}
